/* Author: Mark Faust
 *
 * C version of predictor file
*/

/****************************************************************************
  ECE 486 Project 2
  Branch Prediction

  Jinho Park
  Albert Pham
  Antoni Romano
  Hoa Quach

  predictor.h

  The competition predictor parameter definitions
****************************************************************************/

#ifndef PREDICTOR_H_SEEN
#define PREDICTOR_H_SEEN

// Local History Parameters

#define LOCAL_SIZE			1024
#define GLOBAL_SIZE			1024
#define PC_MASK				0x00000FFC
#define BRANCH_MASK			0x000003FF  
#define GLOBAL_MASK 			0x00000002
#define LOCAL_MASK			0x00000004
#define CHOICE_MASK			0x00000002
#define LOCAL_HISTORY_MASK		0x000003FF //10 bit local history


//Local History Prediction bit definitions 

#define LNT_STRONGLY			0x00
#define LNT_LESS_STRONGLY		0x01
#define LNT_LESS_WEAKLY			0x02
#define LNT_WEAKLY			0x03
#define LT_WEAKLY			0x04
#define LT_LESS_WEAKLY			0x05
#define LT_LESS_STRONGLY		0x06
#define LT_STRONGLY			0x07

//Global Choice Prediction bit definitions

#define GNT_STRONGLY			0x00
#define GNT_WEAKLY			0x01
#define GT_WEAKLY			0x02
#define GT_STRONGLY			0x03

#define LOCAL_CHOSEN			0x02


#define LOCAL_TAKEN			0x04
#define BRANCH_TAKEN			0x01
#define TAKEN				true
#define NOT_TAKEN			false

// Perceptron Parameters

#define PHI				44	
#define HISTORY_LENGTH			16

#define NUM_PERCEPTRONS			128
#define NUM_WEIGHTS			16


#include <cstddef>
#include <cstring>
#include <inttypes.h>
#include <vector>
#include <cmath>
#include "op_state.h"   // defines op_state_c (architectural state) class 
#include "tread.h"      // defines branch_record_c class

// Perceptron predictor functions

int getPerceptronIndex();	// Get the perceptron line indice by hashing the branch address 
int getPrediction();		// Get the prediction returns n > 0 for taken branches

class PREDICTOR
{
    public:
        bool get_prediction( const branch_record_c* br, const op_state_c* os );

        void update_predictor( const branch_record_c* br, const op_state_c* os, bool taken );

};

#endif // PREDICTOR_H_SEEN
